package org.itboys.mobile.controller.weixin;

import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.commons.CommonConstants;
import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.dto.SundayMemberSessionDto;
import org.itboys.mobile.dto.project.ZhongBaoProjectDto;
import org.itboys.mobile.entity.ZhongBaoTag;
import org.itboys.mobile.entity.mongo.SundayComment;
import org.itboys.mobile.entity.mongo.SundayMember;
import org.itboys.mobile.entity.mongo.project.ZhongBaoProject;
import org.itboys.mobile.entity.mongo.project.ZhongBaoProjectInfo;
import org.itboys.mobile.entity.mongo.project.ZhongBaoProjectSign;
import org.itboys.mobile.service.mongo.weixin.*;
import org.itboys.mobile.util.AccountIdHoldUtils;
import org.itboys.mobile.util.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 作者：江雄
 * 时间：2017年5月9日
 * 描述：众包_微信_项目_controller
 */
@Controller
@RequestMapping("/zhongbao/weixin/project")
public class ZhongBaoWeiXinProjectController extends BaseController{
    @Autowired
    private ZhongBaoWeiXinProjectService projectService;
    @Autowired
    private ZhongBaoWeiXinProjectInfoService projectInfoService;
    @Autowired
    private ZhongBaoWeiXinProjectSignService projectSignService;
    @Autowired
    private SundayWeiXinMemberService memberService;
    @Autowired
    private ZhongBaoWeiXinTagService tagService;
    /**
     * 个人中心
     * @param request
     * @param response
     */
    @RequestMapping(value="/input", method= RequestMethod.GET)
    @ApiOperation(value="新增项目-页面")
    public String input(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model

            ){
        try{
           // Thread.sleep(3000);
           // ZhongBaoProjectDto projectDto= projectService.getProjectDetail(id,AccountIdHoldUtils.getSessionMember(request).getId());
          //  model.addAttribute("project",projectDto);
            SundayMemberSessionDto memberSessionDto=AccountIdHoldUtils.getSessionMember(request);
            SundayMember member =memberService.getById(memberSessionDto.getId());
            model.addAttribute("memberDto",member);
            //2018年1月15日，增加用户标签，用于默认地点和行业
            ZhongBaoTag tag =tagService.getTag(memberSessionDto.getId(),0l);
            model.addAttribute("tag",tag);
            //增加返回参数。
            model.addAttribute("returnType",request.getParameter("returnType"));
            return "/zhongbao/weixin/project/input";
        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/input----e="+e.getMessage());
            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }

    /**
     * 新增项目
     * @param request
     * @param response
     * @param
     */
    @RequestMapping(value="/add", method={RequestMethod.POST,RequestMethod.GET})
    @ApiOperation(value="【微信版】新增项目")
    public void add(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(required=true, name="id", value="项目ID。新增传0")@RequestParam(value = "id", required = true)Long id,
            @ApiParam(required=true, name="name", value="项目名称")@RequestParam(value = "name", required = true)String name,
            @ApiParam(required=false, name="keyWords", value="项目关键字。逗号隔开")@RequestParam(value = "keyWords", required = false)String keyWords,
            @ApiParam(required=false, name="startDate", value="开始时间")@RequestParam(value = "startDate", required = false)Date startDate,
            @ApiParam(required=false, name="endDate", value="结束时间")@RequestParam(value = "endDate", required = false)Date endDate,
            @ApiParam(required=false, name="desc", value="项目描述")@RequestParam(value = "desc", required = false)String desc,
            @ApiParam(required=false, name="type", value="项目类型。1，公开的，2私有的")@RequestParam(value = "type", required = false)Integer type,
            @ApiParam(required=false, name="images", value="图片集合")@RequestParam(value = "images", required = false)List<String> images,
            @ApiParam(required=false, name="employeeIds", value="项目关联的员工ID集合。例如:")@RequestParam(value = "employeeIds", required = false)List<Long> employeeIds,
            @ApiParam(required=false, name="trade", value="标签:行业")@RequestParam(value = "trade", required = false)String trade,
            @ApiParam(required=false, name="provinceId", value="标签:省ID.")@RequestParam(value = "provinceId", required = false)Long provinceId,
            @ApiParam(required=false, name="provinceName", value="标签:省名称")@RequestParam(value = "provinceName", required = false)String provinceName,
            @ApiParam(required=false, name="cityId", value="标签:市ID")@RequestParam(value = "cityId", required = false)Long cityId,
            @ApiParam(required=false, name="cityName", value="标签:市名称")@RequestParam(value = "cityName", required = false)String cityName,
            @ApiParam(required=false, name="name1", value="标签:名称1")@RequestParam(value = "name1", required = false)String name1,
            @ApiParam(required=false, name="name2", value="标签:名称2")@RequestParam(value = "name2", required = false)String name2,
            @ApiParam(required=false, name="name3", value="标签:名称3")@RequestParam(value = "name3", required = false)String name3
    ){
        try {
            SundayMemberSessionDto memberSessionDto = AccountIdHoldUtils.getSessionMember(request);
             Long projectId= projectService.addProject(id,memberSessionDto.getId(), name,  keyWords,  startDate,  endDate,desc, type, images, employeeIds, trade,  provinceId,  provinceName,  cityId,  cityName,  name1,  name2,  name3);
            ResponseMessage.success(projectId);
        } catch (Exception e) {

            String msg ="";
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
            }else{
                msg= CommonConstants.ERROMSG;
                logger.info("/zhongbao/weixin/project/add--------"+e);
            }
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,msg);
        }
    }

    /**
     * 项目审核-页面
     * @param request
     * @param response
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(value="/handle/input", method= RequestMethod.GET)
    @ApiOperation(value="审核项目-页面")
    public String handle_input(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model, @ApiParam(required=true, name="id", value="项目ID。0")@RequestParam(value = "id", required = true)Long id
            ){
        try{

            ZhongBaoProjectDto projectDto= projectService.getProjectDetail(id,AccountIdHoldUtils.getSessionMember(request).getId());
            model.addAttribute("project",projectDto);
            return "/zhongbao/weixin/project/handle";
        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/handle/input----e="+e.getMessage());
            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }
    /**
     * 新增项目
     * @param request
     * @param response
     * @param
     */
    @RequestMapping(value="/handle", method=RequestMethod.POST)
    @ApiOperation(value="【微信版】审核项目")
    public void handle(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(required=true, name="id", value="项目ID。0")@RequestParam(value = "id", required = true)Long id,
            @ApiParam(required=true, name="name", value="项目名称")@RequestParam(value = "name", required = true)String name,
            @ApiParam(required=false, name="keyWords", value="项目关键字。逗号隔开")@RequestParam(value = "keyWords", required = false)String keyWords,
            @ApiParam(required=false, name="startDate", value="行业")@RequestParam(value = "startDate", required = false)Date startDate,
            @ApiParam(required=false, name="endDate", value="职位")@RequestParam(value = "endDate", required = false)Date endDate,
            @ApiParam(required=false, name="desc", value="项目描述")@RequestParam(value = "desc", required = false)String desc,
            @ApiParam(required=false, name="type", value="项目类型。1，公开的，2私有的")@RequestParam(value = "type", required = false)Integer type,
            @ApiParam(required=false, name="images", value="图片集合")@RequestParam(value = "images", required = false)List<String> images,
            @ApiParam(required=false, name="employeeIds", value="项目关联的员工ID集合。例如:")@RequestParam(value = "employeeIds", required = false)List<Long> employeeIds,
            @ApiParam(required=true, name="isAgree", value="是否同意审核1是，0否")@RequestParam(value = "isAgree", required = true)boolean isAgree,
            @ApiParam(required=false, name="trade", value="标签:行业")@RequestParam(value = "trade", required = false)String trade,
            @ApiParam(required=false, name="provinceId", value="标签:省ID.")@RequestParam(value = "provinceId", required = false)Long provinceId,
            @ApiParam(required=false, name="provinceName", value="标签:省名称")@RequestParam(value = "provinceName", required = false)String provinceName,
            @ApiParam(required=false, name="cityId", value="标签:市ID")@RequestParam(value = "cityId", required = false)Long cityId,
            @ApiParam(required=false, name="cityName", value="标签:市名称")@RequestParam(value = "cityName", required = false)String cityName,
            @ApiParam(required=false, name="name1", value="标签:名称1")@RequestParam(value = "name1", required = false)String name1,
            @ApiParam(required=false, name="name2", value="标签:名称2")@RequestParam(value = "name2", required = false)String name2,
            @ApiParam(required=false, name="name3", value="标签:名称3")@RequestParam(value = "name3", required = false)String name3

    ){
        try {
            SundayMemberSessionDto memberSessionDto = AccountIdHoldUtils.getSessionMember(request);
         Long projectId=   projectService.handle(id,memberSessionDto.getId(), name,  keyWords,  startDate,  endDate,desc, type, images, employeeIds,isAgree,trade,  provinceId,  provinceName,  cityId,  cityName,  name1,  name2,  name3);
            ResponseMessage.success(projectId);
        } catch (Exception e) {

            String msg ="";
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
            }else{
                msg= CommonConstants.ERROMSG;
                logger.info("/zhongbao/weixin/project/handleProject--------"+e);
            }
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,msg);
        }
    }
    @RequestMapping(value="/index", method= RequestMethod.GET)
    @ApiOperation(value="项目列表页")
    public String index(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model,
            @ApiParam(required=true, name="type", value="1，自己关注的项目，2团体项目，3公共项目")@RequestParam(value = "type", required = true)Integer type
    ){
        try{

            model.addAttribute("type",type);
            //2018年1月18日，增加用户信息
            SundayMemberSessionDto memberSessionDto=AccountIdHoldUtils.getSessionMember(request);
            SundayMember member =memberService.getById(memberSessionDto.getId());
            model.addAttribute("memberDto",member);
            if(type==1){
                return "/zhongbao/weixin/project/index/index1";
            }else if(type==2){
                return "/zhongbao/weixin/project/index/index2";
            }else if(type==3){
                return "/zhongbao/weixin/project/index/index3";
            }else{
                return  null;
            }
          /*  //SundayMember member = memberService.getById(AccountIdHoldUtils.getSessionMember(request).getId());
            //  model.addAttribute("memberDto",member);
            return "/zhongbao/weixin/project/input";*/
        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/index----e="+e.getMessage());

            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }
    @RequestMapping(value="/getData", method= RequestMethod.POST)
    @ApiOperation(value="项目数据页")
    public String getData(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model,
            @ApiParam(required=true, name="type", value="1，自己关注的项目，2团体项目，3公共项目")@RequestParam(value = "type", required = true)Integer type,
            @ApiParam(required = true, name = "pageSize", value = "分页参数。每页数量。默认20") @RequestParam(value = "pageSize", required = true) String pageSize,
            @ApiParam(required = true, name = "pageNumber", value = "分页参数。第几页。默认1") @RequestParam(value = "pageNumber", required = true) String pageNumber,
            @ApiParam(required = false, name = "sort", value = "排序参数。字段名称。默认为空") @RequestParam(value = "sort", required = false) String sort,
            @ApiParam(required = false, name = "order", value = "排序参数。默认为空。ASC正序/DESC倒序") @RequestParam(value = "order", required = false) String order

            ){
        try{

           List<ZhongBaoProjectDto> projects = projectService.getProjects(request,AccountIdHoldUtils.getSessionMember(request).getId(),type);
              model.addAttribute("projects",projects);
            return "/zhongbao/weixin/project/data";
        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/data----e="+e.getMessage());

            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }
    @RequestMapping(value="/detail", method= RequestMethod.GET)
    @ApiOperation(value="项目详情页。需要在详情页判断操作")
    public String detail(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model,
            @ApiParam(required=true, name="projectId", value="项目ID")@RequestParam(value = "projectId", required = true)Long projectId
    ){
        try{

            SundayMemberSessionDto memberDto = AccountIdHoldUtils.getSessionMember(request);
            ZhongBaoProjectDto project=projectService.getProjectDetail(projectId,memberDto.getId());
            model.addAttribute("project",project);
            logger.info("-=--是否转发-==="+project.getIsSpread());
            logger.info("-=--是否关注-==="+project.getIsCollection());
            logger.info("-=--是否报名-==="+project.getIsSign());
            SundayMember member =memberService.getById(memberDto.getId());
            model.addAttribute("memberDto",member);
            return "/zhongbao/weixin/project/detail";
        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/detail----e="+e.getMessage());

            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }
    @RequestMapping(value="/info/index", method= RequestMethod.GET)
    @ApiOperation(value="项目-关注或转发页")
    public String info_index(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model,
            @ApiParam(required=true, name="projectId", value="项目ID")@RequestParam(value = "projectId", required = true)Long projectId,
            @ApiParam(required=true, name="type", value="1，转发，2关注")@RequestParam(value = "type", required = true)Integer type
    ){
        try{
            List<ZhongBaoProjectInfo> infos = projectInfoService.selectNoPage(projectId,type);
            model.addAttribute("infos",infos);
            return "/zhongbao/weixin/project/info/index";
        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/info/index/----e="+e.getMessage());

            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }
    @RequestMapping(value="/info/getData", method= RequestMethod.POST)
    @ApiOperation(value="项目转发，关注列表数据页")
    public String info_getData(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model,
            @ApiParam(required=true, name="projectId", value="项目ID")@RequestParam(value = "projectId", required = true)Long projectId,
            @ApiParam(required=true, name="type", value="1，转发，2关注")@RequestParam(value = "type", required = true)Integer type,

            @ApiParam(required = true, name = "pageSize", value = "分页参数。每页数量。默认20") @RequestParam(value = "pageSize", required = true) String pageSize,
            @ApiParam(required = true, name = "pageNumber", value = "分页参数。第几页。默认1") @RequestParam(value = "pageNumber", required = true) String pageNumber,
            @ApiParam(required = false, name = "sort", value = "排序参数。字段名称。默认为空") @RequestParam(value = "sort", required = false) String sort,
            @ApiParam(required = false, name = "order", value = "排序参数。默认为空。ASC正序/DESC倒序") @RequestParam(value = "order", required = false) String order

    ){
        try{

            List<ZhongBaoProjectInfo> infos = projectInfoService.select(request,projectId,type);
            model.addAttribute("infos",infos);
            return "/zhongbao/weixin/project/info/data";
        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/info/data----e="+e.getMessage());

            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }
    /**
     *
     * @param request
     * @param response
     * @param projectId

     */
    @RequestMapping(value="/info/save", method=RequestMethod.POST)
    @ApiOperation(value="项目关注或转发")
    public void info_save(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(required=true, name="projectId", value="项目ID。")@RequestParam(value = "projectId", required = true)Long projectId,
            @ApiParam(required=true, name="type", value="类型。1转发，2关注收藏")@RequestParam(value = "type", required = true)Integer type
    ){
        try {
            // SundayMemberSessionDto memberSessionDto = AccountIdHoldUtils.getSessionMember(request);
            projectInfoService.save(projectId,AccountIdHoldUtils.getSessionMember(request).getId(), type);
            ResponseMessage.success();
        } catch (Exception e) {

            String msg ="";
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
            }else{
                msg= CommonConstants.ERROMSG;
                logger.info("/zhongbao/weixin/project/info/collection--------"+e);
            }
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,msg);
        }
    }
    /**********************************项目报名相关*******************************/
    @RequestMapping(value="/sign/sign", method=RequestMethod.GET)
    @ApiOperation(value="项目报名_页面")
    public String sign_sign(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model,
            @ApiParam(required=true, name="projectId", value="项目ID")@RequestParam(value = "projectId", required = true)Long projectId
            ){
        try{
            SundayMember memberDto = memberService.getById(AccountIdHoldUtils.getSessionMember(request).getId());
            model.addAttribute("memberDto",memberDto);
            model.addAttribute("projectId",projectId);

            return "/zhongbao/weixin/project/sign/sign";
        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/sign/sign/----e="+e.getMessage());
            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }
    /**
     * 项目报名提交
     * @param request
     * @param response
     * @param projectId
     * @param remark
     */
    @RequestMapping(value="/sign/submit", method=RequestMethod.POST)
    @ApiOperation(value="项目报名-提交数据")
    public void sign_submit(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(required=true, name="projectId", value="项目ID。")@RequestParam(value = "projectId", required = true)Long projectId,
            @ApiParam(required=true, name="nickName", value="用户名称")@RequestParam(value = "nickName", required = true)String nickName,

            @ApiParam(required=true, name="mobile", value="用户电话")@RequestParam(value = "mobile", required = true)String mobile,
            @ApiParam(required=true, name="remark", value="报名留言")@RequestParam(value = "remark", required = true)String remark
    ){
        try {
           // SundayMemberSessionDto memberSessionDto = AccountIdHoldUtils.getSessionMember(request);
            projectSignService.sign( projectId,AccountIdHoldUtils.getSessionMember(request).getId(),nickName,mobile,remark);
            ResponseMessage.success();
        } catch (Exception e) {

            String msg ="";
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
            }else{
                msg= CommonConstants.ERROMSG;
                logger.info("/zhongbao/weixin/project/sign/submit--------"+e);
            }
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,msg);
        }
    }
    /*@RequestMapping(value="/sign/index", method= RequestMethod.GET)
    @ApiOperation(value="项目报名列表页")
    public String sign_index(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model,
            @ApiParam(required=true, name="projectId", value="项目ID")@RequestParam(value = "projectId", required = true)Long projectId
           // @ApiParam(required=true, name="type", value="1，转发，2报名，3关注")@RequestParam(value = "type", required = true)Integer type
    ){
        try{
            model.addAttribute("projectId",projectId);
           // model.addAttribute("type",type);
            return "/zhongbao/weixin/project/sign/index";
          *//*  //SundayMember member = memberService.getById(AccountIdHoldUtils.getSessionMember(request).getId());
            //  model.addAttribute("memberDto",member);
            return "/zhongbao/weixin/project/input";*//*
        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/sign/index----e="+msg);

            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }*/
    @RequestMapping(value="/sign/index", method= RequestMethod.GET)
    @ApiOperation(value="项目报名人数列表页。不分页")
    public String sign_index(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model,
            @ApiParam(required=true, name="projectId", value="项目ID")@RequestParam(value = "projectId", required = true)Long projectId
            // @ApiParam(required=true, name="type", value="1，转发，2报名，3关注")@RequestParam(value = "type", required = true)Integer type
    ){
        try{
            List<ZhongBaoProjectSign> signs = projectSignService.selectNoPage(projectId);
            model.addAttribute("signs",signs);
           ZhongBaoProject project= projectService.getById(projectId);
            model.addAttribute("project",project);
            return "/zhongbao/weixin/project/sign/index";
          /*  //SundayMember member = memberService.getById(AccountIdHoldUtils.getSessionMember(request).getId());
            //  model.addAttribute("memberDto",member);
            return "/zhongbao/weixin/project/input";*/
        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/sign/index----e="+msg);

            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }
    /**
     * 项目报名处理(项目管理员处理)
     * @param request
     * @param response
     * @param projectId
     * @param messageId
     * @param isAgree
     */
    @RequestMapping(value="/sign/handle", method=RequestMethod.POST)
    @ApiOperation(value="项目报名处理(项目管理员处理)")
    public void sign_handle(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(required=true, name="projectId", value="项目ID。")@RequestParam(value = "projectId", required = true)Long projectId,
            @ApiParam(required=true, name="messageId", value="消息ID。")@RequestParam(value = "messageId", required = true)Long messageId,
            @ApiParam(required=true, name="isAgree", value="是否同意。0否1是")@RequestParam(value = "isAgree", required = true)boolean isAgree

    ){
        try {
            // SundayMemberSessionDto memberSessionDto = AccountIdHoldUtils.getSessionMember(request);
            projectSignService.handle(projectId,AccountIdHoldUtils.getSessionMember(request).getId(),messageId,isAgree);
            ResponseMessage.success();
        } catch (Exception e) {

            String msg ="";
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
            }else{
                msg= CommonConstants.ERROMSG;
                logger.info("/zhongbao/weixin/project/sign/handle--------"+e);
            }
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,msg);
        }
    }
    @RequestMapping(value="/sign/getData", method= RequestMethod.POST)
    @ApiOperation(value="项目转发数据页")
    public String sign_getData(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model,
            @ApiParam(required=true, name="projectId", value="项目ID")@RequestParam(value = "projectId", required = true)Long projectId,
            //@ApiParam(required=true, name="type", value="1，转发，2报名，3关注")@RequestParam(value = "type", required = true)Integer type,

            @ApiParam(required = true, name = "pageSize", value = "分页参数。每页数量。默认20") @RequestParam(value = "pageSize", required = true) String pageSize,
            @ApiParam(required = true, name = "pageNumber", value = "分页参数。第几页。默认1") @RequestParam(value = "pageNumber", required = true) String pageNumber,
            @ApiParam(required = false, name = "sort", value = "排序参数。字段名称。默认为空") @RequestParam(value = "sort", required = false) String sort,
            @ApiParam(required = false, name = "order", value = "排序参数。默认为空。ASC正序/DESC倒序") @RequestParam(value = "order", required = false) String order

    ){
        try{

            List<ZhongBaoProjectSign> projects = projectSignService.select(request,projectId,AccountIdHoldUtils.getSessionMember(request).getId());
            model.addAttribute("projects",projects);
            return "/zhongbao/weixin/project/sign/data";
        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/sign/data----e="+e.getMessage());

            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }
    /**
     * 新增项目
     * @param request
     * @param response
     * @param
     */
    @RequestMapping(value="/deal", method=RequestMethod.POST)
    @ApiOperation(value="【微信版】项目确认成交")
    public void deal(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(required=true, name="projectId", value="项目ID。")@RequestParam(value = "projectId", required = true)Long projectId,
            @ApiParam(required=true, name="memberId", value="成交用户ID")@RequestParam(value = "memberId", required = true)Long memberId
           ){
        try {
            //SundayMemberSessionDto memberSessionDto = AccountIdHoldUtils.getSessionMember(request);
            projectService.dealProject(projectId,memberId);
            ResponseMessage.success();
        } catch (Exception e) {

            String msg ="";
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
            }else{
                msg= CommonConstants.ERROMSG;
                logger.info("/zhongbao/weixin/project/deal--------"+e);
            }
            e.printStackTrace();
            ResponseMessage.error(CommonConstants.FAIL_CODE,msg);
        }
    }
    @RequestMapping(value="/sign/ewm", method= RequestMethod.GET)
    @ApiOperation(value="项目报名成功后，进入对应的二维码页面")
    public String sign_ewm(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model,
            @ApiParam(required=true, name="projectId", value="项目ID")@RequestParam(value = "projectId", required = true)Long projectId
    ){
        try{


        //  SundayMember member = memberService.getById(AccountIdHoldUtils.getSessionMember(request).getId());

            //引导关注
            model.addAttribute("projectId",projectId);
            return "/zhongbao/weixin/project/ewm";


        }catch (Exception e){
            String msg =CommonConstants.ERROMSG;
            Integer code= CommonConstants.FAIL_CODE;
            //自定义异常（签名错误）
            if(e.getClass().getSimpleName().equalsIgnoreCase("ErrorException")){
                msg=e.getMessage();
                //token已过期
            }else  if(e.getClass().getSimpleName().equalsIgnoreCase("TokenException")){
                code=CommonConstants.TOKEN_CODE;
                msg=CommonConstants.TOKENMSG;
            }else{
                logger.error("/zhongbao/weixin/project/sign/ewm----e="+msg);

            }
            e.printStackTrace();
            return "/zhongbao/weixin/error";
        }
    }
}
